package com.gxuwz.util;

import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

@Component
public class IDCodeUtil {

    public static final String STUDENT = "S";

    public static final String DEPARTMENT = "D";

    public static final String INSTRUCTOR = "I";

    public static final String USR = "U";

    public String getUserIDCode(){
        int random = this.getRandom();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = formatter.format(new Date());
        String IDCode = USR +format+random;
        return IDCode;
    }

    public String getDepIDCode(){
        int random = this.getRandom();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = formatter.format(new Date());
        String IDCode = DEPARTMENT +format+random;
        return IDCode;
    }

    public String getInstructorIDCode(){
        int random = this.getRandom();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = formatter.format(new Date());
        String IDCode = INSTRUCTOR +format+random;
        return IDCode;
    }

    public String getStudentIDCode(){
        int random = this.getRandom();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = formatter.format(new Date());
        String IDCode = STUDENT +format+random;
        return IDCode;
    }

    public String getLeaveCodeID(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = simpleDateFormat.format(new Date());
        for(int i = 0; i < 3; i++){
            format += this.getRandom();
        }
        return format;
    }

    public Integer getRandom(){
        int random = new Random().nextInt(10);
        return random;
    }

}
